PreviewView
A UIKit view displaying the Camera feed of a CameraPreviewOutput (port of V5's HybridPreviewView.swift).
It can be used directly in UIKit (or wrapped with UIKitView in Compose Multiplatform). The view can be created with a zero frame: the preview layer always follows the view's bounds.
val previewOutput = VisionCamera.createPreviewOutput()
val previewView = PreviewView()
previewView.previewOutput = previewOutput
previewView.resizeMode = PreviewResizeMode.COVER
previewView.gestureControllers = listOf(
VisionCamera.createZoomGestureController().apply { controller = cameraController },
)Constructors
Creates a PreviewView with the given frame.
Creates a PreviewView from the given coder (e.g. from a storyboard).
Creates a PreviewView with a zero frame, to be laid out later.
Properties
The GestureControllers attached to this view, e.g. a ZoomGestureController to install a native pinch-to-zoom gesture, or a TapToFocusGestureController to focus where the user taps.
Called on the main thread when the preview started.
Called on the main thread when the preview stopped.
The CameraPreviewOutput to display, or null to display nothing. The same output can only be displayed by one view at a time.
How the Camera feed is scaled into this view's bounds. Defaults to PreviewResizeMode.COVER.
Functions
Converts the given cameraPoint in camera sensor coordinates into a Point in view coordinates, relative to this view.
Returns a new ScannedObject where all coordinates of the given scannedObject (its bounding box, and the corner points of a ScannedCode) are converted into view coordinates, relative to this view. Uses AVCaptureVideoPreviewLayer.transformedMetadataObject(for:), so orientation, scaling and cropping are taken into account.
Creates a MeteringPoint to focus AE/AF/AWB on with CameraController.focusTo.
Resizes the preview layer to this view's bounds (port of V5's AutoLayerResizingView.swift).
Takes a snapshot of this view's current contents. Like V5, this is not available on iOS: an AVCaptureVideoPreviewLayer cannot be snapshotted.